/**
 * webhook控制器
 * @author xiaoqiang <465633678@qq.com>
 * @created 2018/11/25 00:11:33
 */
const fs = require('fs')
const exec = require('child_process').exec
// webhooks 密码 用户校验
const password = '465633678'
module.exports = async ctx => {
  try {
    // 获取请求数据
    const data = ctx.request.body
    // 判断密码是否正确
    if (data.password === password) {
      // 获取项目名称s
      const projectName = data.project.name
      // 执行shell脚本
      exec(`sh /usr/local/project/webhooks/shell/deploy.sh ${projectName}`, (error, stdout, stderr) => console.log(error, stdout, stderr))
    }
  } catch (e) {
    console.log(e)
  }
}